package com.design_pattern._01_create._06_factory_method;

public abstract class AbstractFactory {
    abstract Vehicle create();

    public static void main(String[] args) {
        AbstractFactory factory = new CarFactory();
        Vehicle vehicle = factory.create();
        System.out.println("张三，乘坐" + vehicle.getClass().getSimpleName());

        AbstractFactory factory2 = new BroomFactory();
        Vehicle vehicle2 = factory2.create();
        System.out.println("张三，乘坐" + vehicle2.getClass().getSimpleName());

    }

}

class CarFactory extends AbstractFactory{

    @Override
    Vehicle create() {
        return new Car();
    }
}

/**
 * 魔法工厂
 */
class BroomFactory extends AbstractFactory{

    @Override
    Vehicle create() {
        return new Broom();
    }
}
